import React, {Component} from 'react';
import FluxTestAction from '../../action/FluxTestAction';
import GameAction from '../../action/GameAction';
import fluxTestStore from '../../stores/FluxTestStore'

const fluxTestAction = new FluxTestAction();
const gameAction = new GameAction();

class FluxTest extends Component {
    constructor(props) {
        super(props);
        this.state = {
            number: 1
        };
        this.click = this.click.bind(this);
        this._onChange = this._onChange.bind(this);
    }

    componentDidMount() {
        fluxTestStore.addChangeListener(this._onChange);
    }

    componentWillUnmount() {
        fluxTestStore.removeChangeListener(this._onChange);
    }

    _onChange() {
        let number = fluxTestStore.getNumber();
        this.setState({
            number: number
        });
    }

    click() {
        fluxTestAction.changeNumber(1);
    }

    render() {
        let {number} = this.state;
        return (
            <div>
                <button onClick={this.click}>测试</button>
                <div>{number}</div>
            </div>
        );
    }
}

export default FluxTest;

